﻿<Page x:Class="Axiom.Hermetica.WPF.Views.MainPage"
	  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	  xmlns:componentmodel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
	  xmlns:mvvm="clr-namespace:Axiom.Hermetica.WPF.ViewModels"
	  xmlns:sampledata="clr-namespace:Axiom.Hermetica.WPF.SampleData"
	  xmlns:converters="clr-namespace:Axiom.Hermetica.WPF.Converters"
	  d:DataContext="{Binding Source={StaticResource SampleData}}"
	  mc:Ignorable="d" 
	  FontFamily="Calibri"
	  AllowDrop="True" Drop="OnDrop" 
	  Loaded="OnLoaded"
	  
	  d:DesignHeight="414" d:DesignWidth="748" Title="MainPage">

	<Page.Resources>
		<ObjectDataProvider x:Key="Model" ObjectType="{x:Type mvvm:ViewModelLocator}" MethodName="GetMainViewModel"/>
		<sampledata:SampleData x:Key="SampleData"/>
		<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
		<converters:NullToDefaultImage x:Key="NullToDefaultImage"/>
		<converters:EmptryToUnknownCategory x:Key="EmptryToUnknownCategory"/>
		<Style TargetType="ListViewItem">
			<Style.Resources>
				<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
			</Style.Resources>
		</Style>
		<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
			<Setter Property="SnapsToDevicePixels" Value="true"/>
			<Setter Property="OverridesDefaultStyle" Value="true"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ListBoxItem">
						<Border Name="Border" Padding="0" SnapsToDevicePixels="true">
							<Border.Style>
								<Style>
									<Setter Property="Border.Background" Value="White"/>
									<Style.Triggers>
										<Trigger Property="Border.IsMouseOver" Value="True">
											<Setter Property="Border.Background" Value="#EEE"/>
											<Setter Property="TextBlock.Foreground" Value="Black"/>
										</Trigger>
									</Style.Triggers>
								</Style>
							</Border.Style>
							<Border.ContextMenu>
								<ContextMenu FontSize="12">
									<MenuItem Header="Open" Click="OnOpen"/>
									<MenuItem Header="Edit" Click="OnEditSelectedItem"/>
									<MenuItem Header="Get Thumbs" Click="OnGetThumbs"/>
									<Separator/>
									<MenuItem Header="Open Folder in File Explorer" Click="OnOpenInExplorer"/>
								</ContextMenu>
							</Border.ContextMenu>
							<ContentPresenter />
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsSelected" Value="true">
								<Setter TargetName="Border" Property="Background" Value="Orange"/>
							</Trigger>
							<Trigger Property="IsEnabled" Value="false">
								<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		<CollectionViewSource x:Key="Books" Source="{Binding Items}">
			<CollectionViewSource.SortDescriptions>
				<componentmodel:SortDescription PropertyName="Name"/>
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>
	</Page.Resources>
	<Page.DataContext>
		<Binding Source="{StaticResource Model}"/>
	</Page.DataContext>

	<Grid>
		<Grid.Background>
			<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
				<GradientStop Color="WhiteSmoke"/>
				<GradientStop Color="#FFDBDBDB" Offset="1"/>
			</LinearGradientBrush>
		</Grid.Background>
		<Grid.RowDefinitions>
			<RowDefinition Height="auto"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
		<Grid>
			<!--<Menu>
				<MenuItem Header="File">
					<MenuItem Header="Save" Click="OnSave"/>
					<MenuItem Header="Get Thumbs" Click="OnGetThumbs"/>
				</MenuItem>
			</Menu>-->
			<TextBox x:Name="SearchTerm" HorizontalAlignment="Right" Width="200" Margin="6"
					 BorderThickness="1"
					 FontSize="10" Text="{Binding SearchTerm, UpdateSourceTrigger=PropertyChanged}" 
					 KeyUp="OnSearchTermKeyDown" GotFocus="OnSearchTermTextBoxGotFocus" LostFocus="OnSearchTermTextBoxLostFocus"
					 VerticalContentAlignment="Center" BorderBrush="#AAA"/>
		</Grid>
		<Grid Grid.Row="1">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="200" MinWidth="80"/>
				<ColumnDefinition Width="*" MinWidth="80"/>
				<ColumnDefinition Width="200" MinWidth="80"/>
			</Grid.ColumnDefinitions>
			<Border Padding="4" Background="{StaticResource ControlBackground}">
				<ListBox ItemsSource="{Binding Categories}" BorderBrush="{x:Null}"
						 SelectedItem="{Binding SelectedCategory}"
						 SelectionChanged="OnCategoryChanged"
						 HorizontalContentAlignment="Stretch">
					<ListBox.ItemTemplate>
						<DataTemplate>
							<Border Height="25">
								<TextBlock Text="{Binding Converter={StaticResource EmptryToUnknownCategory}}" VerticalAlignment="Center"/>
							</Border>
						</DataTemplate>
					</ListBox.ItemTemplate>
				</ListBox>
			</Border>
			<GridSplitter VerticalAlignment="Stretch" HorizontalAlignment="Right" Width="4"/>
			<DockPanel Grid.Column="1" Margin="0,0,4,0" Grid.Row="1">
				<TextBlock DockPanel.Dock="Top" 
						   Text="{Binding Source={StaticResource Books}, Path=Count, StringFormat=Showing {0}}" 
						   Background="{StaticResource ControlBackground}" 
						   TextAlignment="Right" 
						   FontWeight="Bold" 
						   Foreground="Gray"
						   Padding="0,0,40,0"/>
				<ListBox Padding="0" FontSize="10" ItemsSource="{Binding Source={StaticResource Books}}" 
						 x:Name="BookListBox"
						 Background="{StaticResource ControlBackground}"
						 BorderBrush="{x:Null}"
						 KeyDown="OnKeyDown"
						 HorizontalContentAlignment="Stretch" 
						 ItemContainerStyle="{StaticResource ListBoxItemStyle}"
						 SelectionMode="Extended"
						 ScrollViewer.HorizontalScrollBarVisibility="Disabled"                 
						 ScrollViewer.VerticalScrollBarVisibility="Auto"      
						 ScrollViewer.CanContentScroll="True"
						 SelectedItem="{Binding SelectedItem}"
						 SelectionChanged="OnSelectionChanged"
						 SelectedIndex="1"	
						 MouseDoubleClick="OnItemDoubleClick"
						 VirtualizingStackPanel.VirtualizationMode="Recycling">
					<ListBox.ItemTemplate>
						<DataTemplate>
							<Grid Margin="2" Height="40">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="auto"/>
									<ColumnDefinition Width="*"/>
								</Grid.ColumnDefinitions>
								<Image Source="{Binding Image, Converter={StaticResource NullToDefaultImage}}" Stretch="Uniform" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="2" Width="50"/>
								<Grid Grid.Column="1">									
									<Grid.RowDefinitions>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
									</Grid.RowDefinitions>
									<TextBlock Grid.Column="1" Text="{Binding Name}" Foreground="#555" FontSize="13" VerticalAlignment="Top"/>
									<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Category}" Foreground="#6B6B6B"/>
								</Grid>
							</Grid>
						</DataTemplate>
					</ListBox.ItemTemplate>
				</ListBox>
			</DockPanel>
			<GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Right" Width="4"/>
			<Grid Grid.Column="2" Background="{StaticResource ControlBackground}">
				<StackPanel>
					<Grid Margin="1">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="90" />
							<ColumnDefinition Width="*" />
						</Grid.ColumnDefinitions>
						<TextBlock Text="Category" VerticalAlignment="Center" Margin="0,0,10,0" Foreground="Gray"/>
						<TextBlock Text="{Binding SelectedItem.Category}" Grid.Column="1"/>
					</Grid>
					<Grid Margin="1">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="60" />
							<ColumnDefinition Width="*" />
						</Grid.ColumnDefinitions>
						<TextBlock Text="Author" VerticalAlignment="Center" Margin="0,0,10,0" Foreground="Gray"/>
						<TextBlock Text="{Binding SelectedItem.Author}" Grid.Column="1"/>
					</Grid>
					<Border Grid.Column="1" Margin="10">
						<Border.Effect>
							<DropShadowEffect BlurRadius="25" Color="Black"/>
						</Border.Effect>
						<Image Stretch="Uniform" Source="{Binding ElementName=BookListBox,Path=SelectedItem.Image}"/>
					</Border>
				</StackPanel>
			</Grid>
		</Grid>
	</Grid>
</Page>
